﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FC_MFDs.Properties;

namespace FC_MFDs
{
    public partial class Main : Form
    {
        Timer _timer = new Timer(); 
        
        public Main()
        {
            InitializeComponent();

            _timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called
            _timer.Interval = (1000) * (30);              // Timer will tick evert second
            _timer.Enabled = true;                       // Enable the timer
            _timer.Start();                              // Start the timer

        }

        private void timer_Tick(object sender, EventArgs e)
        {
            this.TopMost = true;

            if (_leftMFCD != null && _leftMFCD.Visible)
            {
                _leftMFCD.TopMost = true;
            }

            if (_rightMFCD != null && _rightMFCD.Visible)
            {
                _rightMFCD.TopMost = true;
            }
        }

        private void MainFormClosing(object sender, FormClosingEventArgs e)
        {
            _leftMFCD.Close();
            _rightMFCD.Close();
            
            // Copy window location to app settings
            Settings.Default.mainWindowPos = this.Location;

            // Save settings
            Settings.Default.Save();
        }

        private void MainLoad(object sender, EventArgs e)
        {
            if (Settings.Default.mainWindowPos != null)
            {
                this.Location = Settings.Default.mainWindowPos;
            }
        }

        private LeftMFCD _leftMFCD;
        private RightMFCD _rightMFCD;

        public void setLeftMFCD(LeftMFCD leftMFCD)
        {
            _leftMFCD = leftMFCD;
        }

        public void setRightMFCD(RightMFCD rightMFCD)
        {
            _rightMFCD = rightMFCD;
        }

        private void OnClick_SU25(object sender, EventArgs e)
        {
            _leftMFCD.BackgroundImage = Resources.SU25TL;
            _rightMFCD.BackgroundImage = Resources.SU25TR;

            if (!_leftMFCD.Visible)
            {
                _leftMFCD.Show();
            }

            if (!_rightMFCD.Visible)
            {
                _rightMFCD.Show();
            }
        }

        private void onClick_f15c(object sender, EventArgs e)
        {
            _leftMFCD.BackgroundImage = Resources.F15CL;
            _rightMFCD.BackgroundImage = Resources.F15CR;

            if (!_leftMFCD.Visible)
            {
                _leftMFCD.Show();
            }

            if (!_rightMFCD.Visible)
            {
                _rightMFCD.Show();
            }
        }

        private void onClick_mig29(object sender, EventArgs e)
        {
            _leftMFCD.BackgroundImage = Resources.MG29L;
            _rightMFCD.BackgroundImage = Resources.MG29R;

            if (!_leftMFCD.Visible)
            {
                _leftMFCD.Show();
            }

            if (!_rightMFCD.Visible)
            {
                _rightMFCD.Show();
            }
        }

        private void OnClick_None(object sender, EventArgs e)
        {
            if (_leftMFCD.Visible)
            {
                _leftMFCD.Hide();
            }

            if (_rightMFCD.Visible)
            {
                _rightMFCD.Hide();
            }
        }
    }
}
